icontheme: Don't force missing icon
authorBenjamin Otte <otte@redhat.com>
Sun, 11 May 2014 00:30:50 +0000 (02:30 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 14 May 2014 02:28:34 +0000 (04:28 +0200)
When forcing regular or symbolic icons, fall back to the default
specified icons. This ensures that when no symbolic icon is present, an
icon will still appear - the regular one.

gtk/gtkicontheme.c
gtk/gtkicontheme.h

index 8bf1062fd5ffadaf019c19da18e36069e4fc0640..b06d0fb738c479d84fbe374f3a0ac00475c9a9a5 100644 (file)
@@ -1803,7 +1803,7 @@ choose_icon (GtkIconTheme       *icon_theme,
 {
   gboolean has_regular = FALSE, has_symbolic = FALSE;
   GtkIconInfo *icon_info;
-  gchar **new_names;
+  GPtrArray *new_names;
   guint i;
 
   for (i = 0; icon_names[i]; i++)
@@ -1816,40 +1816,63 @@ choose_icon (GtkIconTheme       *icon_theme,
 
   if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
     {
-      new_names = g_new0 (gchar *, i + 1);
+      new_names = g_ptr_array_new_with_free_func (g_free);
       for (i = 0; icon_names[i]; i++)
         {
           if (g_str_has_suffix (icon_names[i], "-symbolic"))
-            new_names[i] = g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic"));
+            g_ptr_array_add (new_names, g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic")));
           else
-            new_names[i] = g_strdup (icon_names[i]);
+            g_ptr_array_add (new_names, g_strdup (icon_names[i]));
         }
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (g_str_has_suffix (icon_names[i], "-symbolic"))
+            g_ptr_array_add (new_names, g_strdup (icon_names[i]));
+        }
+      g_ptr_array_add (new_names, NULL);
+
+      icon_info = real_choose_icon (icon_theme,
+                                    (const gchar **) new_names->pdata,
+                                    size,
+                                    scale,
+                                    flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+      g_ptr_array_free (new_names, TRUE);
     }
   else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
     {
-      new_names = g_new0 (gchar *, i + 1);
+      new_names = g_ptr_array_new_with_free_func (g_free);
       for (i = 0; icon_names[i]; i++)
         {
           if (!g_str_has_suffix (icon_names[i], "-symbolic"))
-            new_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL);
+            g_ptr_array_add (new_names, g_strconcat (icon_names[i], "-symbolic", NULL));
           else
-            new_names[i] = g_strdup (icon_names[i]);
+            g_ptr_array_add (new_names, g_strdup (icon_names[i]));
+        }
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (!g_str_has_suffix (icon_names[i], "-symbolic"))
+            g_ptr_array_add (new_names, g_strdup (icon_names[i]));
         }
+      g_ptr_array_add (new_names, NULL);
+
+      icon_info = real_choose_icon (icon_theme,
+                                    (const gchar **) new_names->pdata,
+                                    size,
+                                    scale,
+                                    flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+      g_ptr_array_free (new_names, TRUE);
     }
   else
     {
-      new_names = NULL;
+      icon_info = real_choose_icon (icon_theme,
+                                    icon_names,
+                                    size,
+                                    scale,
+                                    flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
     }
 
-  icon_info = real_choose_icon (icon_theme,
-                                new_names ? (const gchar **) new_names : icon_names,
-                                size,
-                                scale,
-                                flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
-
-  if (new_names)
-    g_strfreev (new_names);
-
   return icon_info;
 }
 
index bdbaafe3172f44dc46a824f6882be5e4f1c97401..c11cfabcf9f6cf5ac29576a6c9b9f3c92f035b8e 100644 (file)
@@ -113,10 +113,10 @@ struct _GtkIconThemeClass
  *   fallback, see gtk_icon_theme_choose_icon(). Since 2.12.
  * @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the
  *   requested size. Since 2.14.
- * @GTK_ICON_LOOKUP_FORCE_REGULAR: Always load regular icons, even when
- *   symbolic icon names are given. Since 3.14.
- * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Always load symbolic icons, even when
- *   regular icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_REGULAR: Try to always load regular icons, even
+ *   when symbolic icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Try to always load symbolic icons, even
+ *   when regular icon names are given. Since 3.14.
  * 
  * Used to specify options for gtk_icon_theme_lookup_icon()
  */